<!-- 功能：创建存储池弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月16日 22:30:38 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="创建自精简池" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-form-item label="选择存储池" v-bind="validateInfos.cunChuChi">
        <a-select v-model:value="modelRef.cunChuChi" placeholder="请选择存储池">
          <a-select-option value="cunChuChi-1">存储池-1</a-select-option>
          <a-select-option value="cunChuChi-2">存储池-2</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="未分配空间">
        9.53 GiB
      </a-form-item>
      <a-form-item label="自精简池大小" v-bind="validateInfos.jingJianChiDaXiao">
        <a-row :gutter="12">
          <a-col flex="auto">
            <a-input v-model:value="modelRef.jingJianChiDaXiao" placeholder="请输入精简池大小" />
          </a-col>
          <a-col>
            <a-select v-model:value="modelRef.jingJianChiDaXiaoDanWei" placeholder="请选择精简池大小单位">
              <a-select-option value="MiB">MiB</a-select-option>
              <a-select-option value="GiB">GiB</a-select-option>
              <a-select-option value="TiB">TiB</a-select-option>
            </a-select>
          </a-col>
        </a-row>
      </a-form-item>
      <a-form-item label="空间报警设置" v-bind="validateInfos.kongJianBaoJingSheZhi">
        <a-row :gutter="12">
          <a-col flex="auto">
            <a-input v-model:value="modelRef.kongJianBaoJingSheZhi" placeholder="请输入空间报警设置" />
          </a-col>
          <a-col>
            %
          </a-col>
        </a-row>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  cunChuChi: 'cunChuChi-1',
  jingJianChiDaXiao: '32',
  jingJianChiDaXiaoDanWei: 'GiB',
  kongJianBaoJingSheZhi: ''
})

const rulesRef = reactive({
  cunChuChi: [
    {
      required: true,
      message: '请选择存储池'
    }
  ],
  jingJianChiDaXiao: [
    {
      required: true,
      message: '请输入精简池大小'
    }
  ],
  kongJianBaoJingSheZhi: [
    {
      required: true,
      message: '请输入空间报警设置'
    }
  ]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('创建存储池>>', toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>